package com.example.bittraffic;

import android.os.Bundle;
import android.os.Vibrator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;

public class Activity_News3 extends Activity {
	WebView web;
	Context context = Activity_News3.this;
	String url = "http://m.jnilbo.com"; // 전남 일보
	ProgressBar progressBar;
	final Activity activity = this;

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news3);

		web = (WebView) findViewById(R.id.webview_news3);
		progressBar = (ProgressBar) this.findViewById(R.id.bar);
		WebSettings set = web.getSettings();
		set.setJavaScriptEnabled(true);
		set.setBuiltInZoomControls(true);

		web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

		web.setWebViewClient(new WebViewClient() {

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			};

			@Override
			public void onPageStarted(WebView view, String url,
					android.graphics.Bitmap favicon) {
				super.onPageStarted(view, url, favicon); // 페이지 로딩 시작
				progressBar.setVisibility(View.VISIBLE);
			};

			@Override
			public void onPageFinished(WebView view, String url) { // 페이지 로딩 완료
				super.onPageFinished(view, url);
				progressBar.setVisibility(View.INVISIBLE);
			};

			@Override
			public void onReceivedError(WebView view, int errorCode,
					String description, String fallingUrl) {
				Toast.makeText(activity, "오류: " + description,
						Toast.LENGTH_LONG).show();
			}
		});

		web.setWebChromeClient(new WebChromeClient() {
			public void onProgressChanged(WebView view, int Progress) {
				activity.setProgress(Progress * 100);
			}
		});
		web.loadUrl(url);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
			web.goBack();
			return true;
		} else {
			Intent intent = new Intent(getApplicationContext(),
					Activity_Main.class);
			intent.putExtra("load", 1);
			startActivity(intent);
			finish();
		}
		return super.onKeyDown(keyCode, event);
	}
}